<%--                                                                       --%>
<%-- Copyright (c) 2001-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>

<%@ page language="java" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collections" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.Vector" %>

<%@ page import="com.broadvision.portal.services.InsufficientPermissionException" %>
<%@ page import="com.broadvision.portal.services.PortalComparator" %>
<%@ page import="com.broadvision.portal.services.PortalVisitor" %>
<%@ page import="com.broadvision.portal.services.microsite.Microsite" %>
<%@ page import="com.broadvision.portal.services.microsite.MicrositeFolder" %>
<%@ page import="com.broadvision.portal.foundation.action.util.MicrositeLogic" %>
<%@ page import="com.broadvision.portal.foundation.action.microsite.MicrositeBaseAction" %>
<%@ page import="com.broadvision.web.servlet.SessionVisitor" %>
<%@ page import="org.apache.struts.util.RequestUtils" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<c:if test="${micrositeNaviInfoView.map.isMicrosite}">
  <jsp:include page="search.jsp"/>
</c:if>
<bean:define id="micrositeId" name="micrositeNaviInfoView" property="urlParams.micrositeId" />

<logic:notEmpty name="micrositeNaviInfoView" property="urlParams.currentAction">
  <bean:define id="currentAction" name="micrositeNaviInfoView" property="urlParams.currentAction" />
</logic:notEmpty>
<logic:empty name="micrositeNaviInfoView" property="urlParams.currentAction">
  <%-- If no currentAction defined, we just set it to "home". --%>
  <bean:define id="currentAction" value="home" />
</logic:empty>

<bean:define id="displayPhaseId" name="micrositeNaviInfoView" property="urlParams.displayPhaseId" />

<% 
  PortalVisitor portalVisitor = SessionVisitor.getInstance(request.getSession()).getPortalVisitor();

  // check whether the microsite object has been cached in request
  Microsite ms = (Microsite)request.getAttribute(MicrositeBaseAction.MICROSITE_OBJECT);
  if (ms == null) {
     ms = new Microsite(portalVisitor.getContext().getServiceId(),
                  ((Long)pageContext.getAttribute("micrositeId")).longValue(),
                  portalVisitor);
     // store the request in the request so that it can be reused in
     // the forwarded action class and micrositeMenu.jsp
     request.setAttribute(MicrositeBaseAction.MICROSITE_OBJECT, ms);
  }

  final boolean displaySetupLink = MicrositeLogic.displaySetupLink(ms, portalVisitor);
  final boolean displaySummaryLink = MicrositeLogic.displaySummaryLink(ms, portalVisitor);

  final long templateId = ms.getTemplateId();
  pageContext.setAttribute("templateId", new Long(templateId));

  final boolean isOwnerable = portalVisitor.isServiceAdmin() || portalVisitor.isSiteAdmin() || ms.isOwner(portalVisitor);
  pageContext.setAttribute("isOwnerable", isOwnerable ? Boolean.TRUE : Boolean.FALSE);
  //
  // Check if the user can access documents.
  //
  Boolean accessDocuments = Boolean.FALSE;
  if ( isOwnerable ) {
    accessDocuments = Boolean.TRUE;
  } else {
    try {
      MicrositeFolder msRootFolder = ms.getRootFolder();
      accessDocuments = Boolean.TRUE;
    }
    catch (InsufficientPermissionException ex) {
      accessDocuments = Boolean.FALSE;
    }
  }
  pageContext.setAttribute("accessDocuments", accessDocuments);

%>
<%
  String styleTag, currentUrl;
  Map params;
%>
<div class="menuBlocktitle">	
  <span>
    <c:if test="${micrositeNaviInfoView.map.isMicrosite}">
      <bean:message key="cs.menu.microsite"/>
    </c:if>
    <c:if test="${!micrositeNaviInfoView.map.isMicrosite}">
      <bean:message key="cs.menu.collaboration"/>
    </c:if>
  </span>
</div>

<div class="menuBlockWrap">
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="Microsite Menu">
  <%if(displaySetupLink) {%>
    
    <%
      styleTag = getStyleTag(pageContext, "setup");
      params = getParamsMap(pageContext, "setup");
      currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/setupCollaboration.do",
                                           params,
                                           null,
                                           false);
    %>
  <tr class="<%=styleTag%>"> 
    <td class="<%=styleTag%>" width="20%">
      <logic:equal name="currentAction" value="setup">
        <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:equal> 
      <logic:notEqual name="currentAction" value="setup">
	<a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif" width="8" height="18" border="0" align="left"/></a>
      </logic:notEqual>
    </td>
    <td class="<%=styleTag%>" width="70%">
      <a href="<%=currentUrl%>">
        <bean:message key="cs.setup.collaboration"/>
      </a>
    </td>
    <td class="<%=styleTag%>" width="10%">
      &nbsp;
    </td>
  </tr>
  <%}%>
    <%
      styleTag = getStyleTag(pageContext, "home");
      params = getParamsMap(pageContext, "home");
      currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/micrositeHome.do",
                                           params,
                                           null,
                                           false); 
    %>
    <tr class="<%=styleTag%>">
    <td class="<%=styleTag%>" width="20%">
      <logic:equal name="currentAction" value="home">
        <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:equal> 
      <logic:notEqual name="currentAction" value="home">
	<a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:notEqual>
    </td>
    <td class="<%=styleTag%>" width="70%">
      <a href="<%=currentUrl%>">
        <bean:message key="cs.home"/>
      </a>
    </td>
    <td class="<%=styleTag%>" width="10%">
      &nbsp;
    </td>
  </tr>
  
    <%styleTag = getStyleTag(pageContext, "overview"); 
      params = getParamsMap(pageContext, "overview");
      currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/overview.do",
                                           params,
                                           null,
                                           false); 

    %>
    <tr class="<%=styleTag%>">
    <td class="<%=styleTag%>" width="20%">
      <logic:equal name="currentAction" value="overview">
        <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:equal> 
      <logic:notEqual name="currentAction" value="overview">
	<a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:notEqual>
    </td> 
    <td class="<%=styleTag%>" width="70%">
      <a href='<%=currentUrl%>'>
        <bean:message key="cs.overview"/>
      </a>
    </td>
    <td class="<%=styleTag%>"  width="10%">
      &nbsp;
    </td>
  </tr>
  
    <%styleTag = getStyleTag(pageContext, "announcements");
      params = getParamsMap(pageContext, "announcements");
      currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/announcementList.do",
                                           params,
                                           null,
                                           false); 
    %>
    <tr class="<%=styleTag%>">
    <td class="<%=styleTag%>" width="20%"> 
      <logic:equal name="currentAction" value="announcements">
        <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:equal> 
      <logic:notEqual name="currentAction" value="announcements">
	<a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:notEqual>
    </td> 
    <td class="<%=styleTag%>" width="70%"> 
      <a href='<%=currentUrl%>'>
        <bean:message key="cs.announcements"/>
      </a>
    </td>
    <td class="<%=styleTag%>" width="10%">
      &nbsp;
    </td>
  </tr>

    <%styleTag = getStyleTag(pageContext, "checklists");
      params = getParamsMap(pageContext, "checklists");
      currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/checklistList.do",
                                           params,
                                           null,
                                           false); 
    %> 
    <tr class="<%=styleTag%>">
    <td class="<%=styleTag%>" width="20%">
      <logic:equal name="currentAction" value="checklists">
        <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:equal> 
      <logic:notEqual name="currentAction" value="checklists">
	<a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:notEqual>
    </td>
    <td class="<%=styleTag%>" width="70%">
      <a href="<%=currentUrl%>">
        <bean:message key="cs.checklists"/>
      </a>
    </td>
    <td class="<%=styleTag%>" width="10%">
     &nbsp;
    </td>
  </tr>
  
    <%styleTag = getStyleTag(pageContext, "discussions");
      params = getParamsMap(pageContext, "discussions");
      currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/discussionList.do",
                                           params,
                                           null,
                                           false); 
    %> 
    <tr class="<%=styleTag%>">
    <td class="<%=styleTag%>" width="20%">
      <logic:equal name="currentAction" value="discussions">
        <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:equal> 
      <logic:notEqual name="currentAction" value="discussions">
	<a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:notEqual>
    </td>
    <td class="<%=styleTag%>" width="70%">
      <a href="<%=currentUrl%>">
      	<bean:message key="cs.discussions"/>
      </a>
    </td>
    <td class="<%=styleTag%>" width="10%">
     &nbsp;
    </td>
  </tr>
  <logic:equal name="accessDocuments" value="true">
    
      <%styleTag = getStyleTag(pageContext, "documents");
      params = getParamsMap(pageContext, "documents");
      params.put("phaseId", (Long)pageContext.getAttribute("displayPhaseId"));
      currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/documentIndex.do",
                                           params,
                                           null,
                                           false); 

      %>
      <tr class="<%=styleTag%>">
      <td class="<%=styleTag%>" width="20%">
      <logic:equal name="currentAction" value="documents">
        <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:equal> 
      <logic:notEqual name="currentAction" value="documents">
        <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:notEqual>
      </td>
      <td class="<%=styleTag%>" width="70%">
        <a href="<%=currentUrl%>">
          <bean:message key="cs.documents"/>
        </a>
      </td>
      <td class="<%=styleTag%>"  width="10%">
        &nbsp;
      </td>
    </tr>
  </logic:equal>
  
      <%styleTag = getStyleTag(pageContext, "meetings");
      params = getParamsMap(pageContext, "meetings");
      currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/meetingList.do",
                                           params,
                                           null,
                                           false); 
      %>
      <tr class="<%=styleTag%>">
      <td class="<%=styleTag%>" width="20%">
      <logic:equal name="currentAction" value="meetings">
        <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:equal> 
      <logic:notEqual name="currentAction" value="meetings">
        <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
      </logic:notEqual>
      </td>
      <td class="<%=styleTag%>" width="70%">
        <a href="<%=currentUrl%>">
          <bean:message key="cs.meetings"/>
        </a>
      </td>
      <td class="<%=styleTag%>"  width="10%">
        &nbsp;
      </td>
    </tr>
    
      <%styleTag = getStyleTag(pageContext, "todos");
        params = getParamsMap(pageContext, "todos");
        currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/taskList.do",
                                           params,
                                           null,
                                           false); 
        %>
        <tr class="<%=styleTag%>">
        <td class="<%=styleTag%>" width="20%">
        <logic:equal name="currentAction" value="todos">
          <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
        </logic:equal> 
        <logic:notEqual name="currentAction" value="todos">
          <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
        </logic:notEqual>
        </td>
        <td class="<%=styleTag%>" width="70%">
          <a href="<%=currentUrl%>">
            <bean:message key="cs.todos"/>
          </a>
        </td>
        <td class="<%=styleTag%>"  width="10%">
          &nbsp;
        </td>
      </tr>
      <%-- program menu --%>
      
      <c:if test="${micrositeNaviInfoView.map.isMicrosite}">
      
      <%styleTag = getStyleTag(pageContext, "program");
        params = getParamsMap(pageContext, "program");
        currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/programList.do",
                                           params,
                                           null,
                                           false); 
        %> 
        <tr class="<%=styleTag%>">
        <td class="<%=styleTag%>" width="20%">
        <logic:equal name="currentAction" value="program">
          <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
        </logic:equal> 
        <logic:notEqual name="currentAction" value="program">
          <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
        </logic:notEqual>
        </td>
        <td class="<%=styleTag%>" width="70%">
          <a href="<%=currentUrl%>">
            <bean:message key="cs.programs"/>
          </a>
        </td>
        <td class="<%=styleTag%>"  width="10%">
          &nbsp;
        </td>
      </tr>
      
      <%-- start contact menu item --%>
      
      <%styleTag = getStyleTag(pageContext, "contact");
        params = getParamsMap(pageContext, "contact");
        currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/contactList.do",
                                           params,
                                           null,
                                           false); 
        %> 
        <tr class="<%=styleTag%>">
        <td class="<%=styleTag%>" width="20%">
        <logic:equal name="currentAction" value="contact">
          <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
        </logic:equal> 
        <logic:notEqual name="currentAction" value="contact">
          <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
        </logic:notEqual>
        </td>
        <td class="<%=styleTag%>" width="70%">
          <a href="<%=currentUrl%>">
            <bean:message key="cs.contacts"/>
          </a>
        </td>
        <td class="<%=styleTag%>"  width="10%">
          &nbsp;
        </td>
      </tr>

      </c:if>
      <%-- end contact menu item --%>
      
      <logic:equal name="isOwnerable" value="true">
       
          <%styleTag = getStyleTag(pageContext, "participants");
          params = getParamsMap(pageContext, "participants");
          currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/participantList.do",
                                           params,
                                           null,
                                           false); 
          %>
          <tr class="<%=styleTag%>">
          <td class="<%=styleTag%>" width="20%">
          <logic:equal name="currentAction" value="participants">
            <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
          </logic:equal> 
          <logic:notEqual name="currentAction" value="participants">
            <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
          </logic:notEqual>
          </td>
          <td class="<%=styleTag%>" width="70%">
            <a href="<%=currentUrl%>">
              <bean:message key="cs.participants"/>
            </a>
          </td>
          <td class="<%=styleTag%>"  width="10%">
           &nbsp;
          </td>
        </tr>
        
          <%styleTag = getStyleTag(pageContext, "groups");
          params = getParamsMap(pageContext, "groups");
          currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/groupList.do",
                                           params,
                                           null,
                                           false); 
          %>
          <tr class="<%=styleTag%>">
          <td class="<%=styleTag%>" width="20%">
            <logic:equal name="currentAction" value="groups">
              <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
            </logic:equal> 
            <logic:notEqual name="currentAction" value="groups">
	      <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
            </logic:notEqual>
          </td>
          <td class="<%=styleTag%>" width="70%">
            <a href="<%=currentUrl%>">
              <bean:message key="cs.groups"/>
            </a>
          </td>
          <td class="<%=styleTag%>"  width="10%">
            &nbsp;
          </td>
        </tr>
      </logic:equal> <%-- End of 'isOwnerable' section. --%>

      <logic:equal name="micrositeNaviInfoView" property="micrositeTemplatePhaseFlag" value="true" scope="request">
      <logic:equal name="isOwnerable" value="true">
        
          <%styleTag = getStyleTag(pageContext, "phases");
          params = getParamsMap(pageContext, "phases");
          currentUrl = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           "/cs/phaseList.do",
                                           params,
                                           null,
                                           false); 
          %>
          <tr class="<%=styleTag%>">
          <td class="<%=styleTag%>" width="20%">
            <logic:equal name="currentAction" value="phases">
              <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
            </logic:equal> 
            <logic:notEqual name="currentAction" value="phases">
	      <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
            </logic:notEqual>
          </td>
          <td class="<%=styleTag%>" width="70%">
            <a href="<%=currentUrl%>">
              <bean:message key="cs.phases"/>
            </a>
          </td>
          <td class="<%=styleTag%>"  width="10%">
            &nbsp;
          </td>
        </tr>
        </logic:equal>
        </logic:equal> <%-- end of: micrositeTemplatePhaseFlag && isOwnerable --%>
        <%if(displaySummaryLink) {%>
        
        <%
          styleTag = getStyleTag(pageContext, "summary");
          params = getParamsMap(pageContext, "summary");
          currentUrl = RequestUtils.computeURL(pageContext,
                                               null,
                                               null,
                                               "/cs/collaborationCloseSummary.do",
                                               params,
                                               null,
                                               false);
        %>
        <tr class="<%=styleTag%>">
        <td class="<%=styleTag%>" width="20%">
          <logic:equal name="currentAction" value="summary">
            <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem_white.gif"  width="8" height="18" border="0" align="left"/></a>
          </logic:equal> 
          <logic:notEqual name="currentAction" value="summary">
	    <a href="<%=currentUrl%>"><html:img page="/cs/images/icons/licon_selecteditem.gif"  width="8" height="18" border="0" align="left"/></a>
          </logic:notEqual>
        </td>
        <td class="<%=styleTag%>" width="70%">
          <a href="<%=currentUrl%>">
            <c:if test="${micrositeNaviInfoView.map.isMicrosite}">
              <bean:message key="cs.summary"/>
            </c:if>
            <c:if test="${!micrositeNaviInfoView.map.isMicrosite}">
              <bean:message key="cs.summary.collaboration"/>
            </c:if>
          </a>
        </td>
        <td class="<%=styleTag%>" width="10%">
          &nbsp;
        </td>
      </tr>
      <%}%>
   </table>
      
</div>      
<%!
private String getStyleTag(PageContext page, String menu){
  String curAction = (String)page.getAttribute("currentAction");
  return menu.equalsIgnoreCase(curAction) ? "menuOn" : "menuOff";
}

private Map getParamsMap(PageContext pageContext, String currentAction){
  Map result;
  result = new HashMap(3);
  result.put("micrositeId", (Long)pageContext.getAttribute("micrositeId"));
  result.put("displayPhaseId", (Long)pageContext.getAttribute("displayPhaseId"));
  result.put("currentAction", currentAction);
  return result;  
}
%>
